package com.zls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zls.mapper.TProducterMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.TFarm;
import com.zls.pojo.TProducter;
import com.zls.pojo.TTask;
import com.zls.service.TFarmService;
import com.zls.service.TProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TProducerServiceImpl extends ServiceImpl<TProducterMapper, TProducter> implements TProducerService {
    @Autowired
    private TProducterMapper tProducterMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<TProducter> page = tProducterMapper.findPage((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = tProducterMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Autowired
    private TFarmService tFarmService;
    @Override
    @Transactional
    public int addTpro(TProducter tProducter) {
        tProducter.setCreatedate(new Date());
        TFarm tFarm = tFarmService.selectId(tProducter.getFarmId());
        tProducter.setSysUserId(tFarm.getUserId());
        int insert = tProducterMapper.insert(tProducter);
        return insert;
    }

    @Override
    public TProducter selectById(int id) {
        return tProducterMapper.selectId(id);
    }

    @Override
    public TProducter login(TProducter tProducter) {
        return tProducterMapper.login(tProducter);

    }
}
